"""
@Author  : 康帅
@Time    : 2021/2/2 18:01
@Function: 题目在dushu.pdf
"""


class Solution:
    @staticmethod
    def read_file(file_name):
        with open(file_name) as f:
            content = f.read().strip().split("\n")
        contents = [i.split() for i in content]
        return contents

    @staticmethod
    def check(sudo_ku):
        pooled = sudo_ku[0] + sudo_ku[1] + sudo_ku[2]
        data_list = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
        if set(pooled) is set(data_list):
            return True
        return False

    @staticmethod
    def valid(contents):
        span = contents[0][0]
        areas = int(int(span) / 3)
        valid = 0
        data = [(i * 3, j * 3) for i in range(areas) for j in range(areas)]
        del contents[0]
        current = [row[data[0][0]:data[0][0] + 3] for row in contents[data[0][1]:data[0][1] + 3]]
        if Solution.check(current) and valid is areas ** 2:
            valid += 1
            return True
        else:
            return False


if __name__ == '__main__':
    contents = Solution.read_file("sudoku5.txt")
    try:
        print(contents, Solution.valid(contents))
    except Exception as e:
        print(e)
